import os

from Server.File import fetch_file,File,Folder
from Server.Node import Node
from Server.Filter import filter_list


def fetch_file_status(path, node: Node = None):
    if not node:
        file = fetch_file(path)
    else:
        file = node.fetch_file(path)
    return file.stat

def fetch_folder_list(path,node:Node=None,filters=()):
    if not node:
        folder = Folder(path,'')
        tmp = folder.sub_all()
        for filtername in filters:
            tmp = filter_list[filtername](tmp)
        abs_tmp = [os.path.join(path,filename) for filename in tmp]
        return [fetch_file_status(filename) for filename in abs_tmp]
    else:
        raise Exception("Functional:fetch_folder_list||未完成此函数")